import { defineStore } from "pinia";
import request from "@/utils/request";
import { ref } from "vue";
import type { ApiRes, GoodsInfo } from "@/types/data";

const useGoodsStore = defineStore("goods", () => {
  // 根据id获取商品详情
  const goodsInfo = ref({} as GoodsInfo);
  const getGoodsInfo = async (id: string) => {
    const res = await request.get<ApiRes<GoodsInfo>>("/goods", {
      params: { id: id },
    });
    goodsInfo.value = res.data.result;
  };

  return {
    goodsInfo,
    getGoodsInfo,
  };
});

export default useGoodsStore;
